<?php
/*
Description: session manager class
*/
include_once("model/users.php");
class Session {
    	
	public static function is_logged_in(){
	  //return isset($_SESSION['username']);
	  return isset($_SESSION['user_id']);
	}
	
	public static function user(){
	  //return $_SESSION['username'];
	  $user = new Users();
	  $user->find_by_id($_SESSION['user_id']);
	  return $user;
	}
	
	public static function stop(){
	  //if(isset($_SESSION['username']))
		//unset($_SESSION['username']);
	  if(isset($_SESSION['user_id']))
		unset($_SESSION['user_id']);
	}
	
	public static function start($username){
	  //$_SESSION['username'] = $username;
	  $user = new Users();
	  $user->find_by_username($username);
	  $_SESSION['user_id'] = $user->id;
	}
	
	public static function set_error($str){
		$_SESSION['flash_error'] = $str;
	}
	
	public static function has_error(){
		return isset($_SESSION['flash_error']);
	}
	
	public static function get_error_message(){
		if(isset($_SESSION['flash_error'])){
			$result = $_SESSION['flash_error'];
			unset($_SESSION['flash_error']);
			return $result;
		}
	}
}
?>